package ajaxjs.sql;

import javax.script.ScriptException;

import ajaxjs.js.JsRuntime;
public class Handler{
	private JsRuntime js = null;
	public Handler(JsRuntime js){
		setJs(js);
		
		String SSJS_Path = ajaxjs.config.Application.Rhino_Path;
		
		if(System.getProperty("java.version").startsWith("1.6")){
			js.load(SSJS_Path + "/libs/json2.js");
		}
		
		this.js.load(SSJS_Path + "/common.js");
		this.js.load(SSJS_Path + "/db/pojo.js");
		this.js.load(SSJS_Path + "/db/service_utils.js");
		this.js.load(SSJS_Path + "/db/service.js");
		this.js.load(SSJS_Path + "/db/controller.js");	
	}
	public JsRuntime getJs() {
		return js;
	}
	public void setJs(JsRuntime js) {
		this.js = js;
	}
	
	public Object getValue2JSON(java.sql.ResultSet resultset){
		try {
			return js.call("getValue2JSON", resultset);
		} catch (ScriptException e) {
			System.err.println("getValue2JSON 转换为 json 时失败！");
			return null;
		}
	}
}
